<template>

  <el-container style="height: 100vh;width:100%;background-color: rgb(238, 241, 246);">
    <!--      style="box-shadow: 2px 0 6px rgb(0 21 41 ) style=" background-color: rgb(238, 241, 246);"box-shadow: 6px 6px 6px rgb(0 21 41 );margin:0;padding:0-->
    <el-aside :width="sideWidth+'px'">
      <Aside :isCollapse="isCollapse" style="" :logoTextShow="logoTextShow"/>
    </el-aside>

    <el-container style="margin:0; padding:0;">
      <el-header style="border-bottom: 1px solid #cccccc;height: 50px;background-color: rgba(124,198,214,0.78)">
        <Header :collapseBtnClass="collapseBtnClass" :collapse="collapse" :user="user"/>
      </el-header>

      <el-main>
        <!--          表示当前页面的子路由会在router-view里面展示-->
        <router-view @refreshUser="getUser"/>
      </el-main>
    </el-container>

  </el-container>

</template>

<script>

import Aside from "@/components/Aside";
import Header from "@/components/Header";

export default {
  name: 'HomeView',
  data() {
    return {

      msg: "hello world",
      collapseBtnClass: 'el-icon-s-fold',
      isCollapse: false,
      sideWidth: 200,
      logoTextShow: true,
      user: {},
    }
  },
  created() {
    //从后台获取数据
    this.getUser()
  },
  components: {
    Aside,
    Header
  },
  methods: {
    collapse() {  //点击收缩按钮触发
      this.isCollapse = !this.isCollapse;
      if (this.isCollapse) {//收缩
        this.sideWidth = 64
        this.collapseBtnClass = 'el-icon-s-unfold'
        this.logoTextShow = false;
      } else {      //展开
        this.sideWidth = 200
        this.collapseBtnClass = 'el-icon-s-fold'
        this.logoTextShow = true;
      }
    },
    getUser() {
      let username = localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")).username : ""
      //从后台获取user数据
      this.request.get("/user/username/" + username).then(res => {
        this.user = res.data
      })
    },

  }

}
</script>


